package com.nine.algorithm.recursion.binarysearch;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author nine
 * @version 1.0
 * @description
 * @date 24/4/30 22:43
 */
public class TestBinarySearch {

	/**
	 * 递归二分查找
	 */
	@Test
	@DisplayName("测试 binarySearchBasic")
	public void test1() {
		int[] a = {7, 13, 21, 30, 38, 44, 52, 53};
		assertEquals(0, BinarySearch.search(a, 7));
		assertEquals(1, BinarySearch.search(a, 13));
		assertEquals(2, BinarySearch.search(a, 21));
		assertEquals(3, BinarySearch.search(a, 30));
		assertEquals(4, BinarySearch.search(a, 38));
		assertEquals(5, BinarySearch.search(a, 44));
		assertEquals(6, BinarySearch.search(a, 52));
		assertEquals(7, BinarySearch.search(a, 53));

		assertEquals(-1, BinarySearch.search(a, 0));
		assertEquals(-1, BinarySearch.search(a, 15));
		assertEquals(-1, BinarySearch.search(a, 60));

	}

}

